package main

import (
	"fmt"
	"github.com/Shopify/sarama"
	"os"
	"os/signal"
)

// 广播消费，单个消费，群组消费

// 消费者
func main() {
	addr := []string{"192.168.72.133:9092"}
	config := sarama.NewConfig()
	config.Consumer.Return.Errors = false
	config.Version = sarama.V0_10_2_0
	consumer, err := sarama.NewClient(addr, config)
	if err != nil {
		fmt.Println(err)
	}
	defer func() {
		if err := consumer.Close(); err != nil {
			fmt.Println("关闭错误：", err)
		}
	}()

	groupConsumer, err := sarama.NewConsumerGroupFromClient("test_group_1", consumer)
	if err != nil {
		fmt.Println(err)
	}
	defer func() {
		if err := groupConsumer.Close(); err != nil {
			fmt.Println(err)
		}
	}()

	signals := make(chan os.Signal)
	signal.Notify(signals, os.Interrupt)
	consumed := 0
	fmt.Println("Consumed:", consumed)
}
